package com.cea.papyrustest.uml.deletecommand;

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.commands.UMLElementDeleteCommand;

/**
 * Test class for {@link Connector} factory
 * @author Patrick Tessier
 */
public class ConnectorDeleteCommandTest extends PapyrusCommandTest{

	/** created temp class */
	protected Class class_0;
	
	protected final static String NAME = "Connector0";
	
	/**
	 * Default constructor
	 * @param name the name oif the test case
	 */
	public ConnectorDeleteCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		class_0=(Class)model.getPackagedElement("Class_0");
		if(class_0 == null) {
			fail("impossible to find class");
		}
		Connector connector = class_0.getOwnedConnector(NAME);
		if(connector == null) {
			fail("impossible to find connector");
		}
		papyrusCommand= new UMLElementDeleteCommand(connector,class_0);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		assertNull("the connector exist!",class_0.getOwnedConnector(NAME));
		
		// undo
		stack.undo();
		Element clazz=class_0.getOwnedConnector(NAME);
		assertNotNull("the connector is not re-created",clazz);
		assertTrue("this is not a connector", ((clazz)instanceof Connector));
		
		// redo
		stack.redo();
		assertNull("the connector exist!",class_0.getOwnedConnector(NAME));
	}
}
